package com.liuweiheng.springcloud.controller;

import com.liuweiheng.springcloud.service.PaymentService;
import com.netflix.discovery.converters.Auto;
import lombok.extern.slf4j.Slf4j;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 测试Hystrix服务降级
 *
 * @author lwh
 */
@Slf4j
@RestController
@RequestMapping("/payment/hystrix")
public class PaymentController {

    @Autowired
    private Logger log;

    @Autowired
    private PaymentService paymentService;

    @GetMapping("/ok/{id}")
    public String paymentInfoOk(@PathVariable("id") int id) {
        String result = paymentService.paymentInfoOk(id);
        log.info("******result：" + result);
        Queue<Integer> queue = new LinkedList<>();
        return result;
    }

    @GetMapping("/timeout/{id}")
    public String paymentInfoTimeout(@PathVariable("id") int id) {
        String result = paymentService.paymentInfoTimeout(id);
        log.info("******result：" + result);
        return result;
    }


    @GetMapping("/circuit/{id}")
    public String paymentCirucuit(@PathVariable("id") Integer id) {
            String result = paymentService.paymentCircuitBreaker(id);
            log.info("******result：" + result);
            return result;
    }

}
